﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using XmlStudio.ViewModel.Node;

namespace XmlStudio.Dialogs {
    /// <summary>
    /// Interaction logic for EditTextNodeDialog.xaml
    /// </summary>
    // ReSharper disable RedundantExtendsListEntry
    public partial class EditTextNodeDialog : Window {
        // ReSharper restore RedundantExtendsListEntry
        #region Fields

        #endregion

        #region Properties
        public XmlTextViewModel TextNode { get; set; }
        #endregion

        #region Constructors
        public EditTextNodeDialog() {
            InitializeComponent();
        }

        public EditTextNodeDialog(XmlTextViewModel textNode)
            : this() {
            this.TextNode = textNode;
            this.DataContext = this.TextNode;
        }
        #endregion

        #region Event handlers
        protected override void OnInitialized(EventArgs e) {
            base.OnInitialized(e);

            this.textTextBox.Focus();
        }

        private void OKClicked(object sender, RoutedEventArgs e) {
            BindingExpression textExpression = textTextBox.GetBindingExpression(TextBox.TextProperty);

            if (textExpression != null) textExpression.UpdateSource();

            this.DialogResult = true;
            this.Close();
        }
        #endregion
    }
}
